//
//  TWMineViewController.swift
//  EyepetizerImitative
//
//  Created by 田伟 on 2017/3/9.
//  Copyright © 2017年 个人. All rights reserved.
//  我的页面

import UIKit

class TWMineViewController: UIViewController {

    fileprivate lazy var headerView = TWMineHeaderView.createMineHeaderView()
    fileprivate lazy var tableView = UITableView()
    fileprivate var dataArray = [String]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupHeaderView()
        setupTableView()
        setupData()
    }
    fileprivate func setupData(){
        dataArray = ["我的消息","我的关注","我的缓存","功能开关","我要投稿","意见反馈"]
        tableView.reloadData()
    }
}

// MARK:- UI界面
extension TWMineViewController {
    fileprivate func setupHeaderView(){
        headerView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 250)
        headerView.mineHeaderViewDelegate = self
        view.addSubview(headerView)
    }
    fileprivate func setupTableView(){
        tableView.frame = CGRect(x: 0, y: 250, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height - 250)
        tableView.rowHeight = 80
        tableView.showsVerticalScrollIndicator = true
        tableView.separatorStyle = .none
        tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 44, right: 0)
        tableView.dataSource = self
        tableView.delegate = self
        
        tableView.register(UINib(nibName: "TWMineCell", bundle: nil), forCellReuseIdentifier: "mineCell")
        view.addSubview(tableView)
        
        // footer
        let footer = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 40))
        let label = UILabel(frame: footer.frame)
        label.text = "veision 3.3.0 build 2412"
        label.textAlignment = .center
        label.font = UIFont(name: "FZLTXIHJW--GB1-0", size: 10)
        footer.addSubview(label)
        tableView.tableFooterView = footer
    }
}

// MARK:- ----代理方法----
extension TWMineViewController : UITableViewDataSource, UITableViewDelegate{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArray.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "mineCell", for: indexPath) as! TWMineCell
        cell.mineLabel.text = dataArray[indexPath.row]
        return cell
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print(dataArray[indexPath.row])
    }
}


extension TWMineViewController : TWMineHeaderViewDelegate {
    func MineHeaderViewLoginIconButtonDidClick() {
        print("登录")
        let loginVc = TWLoginViewController()
        present(loginVc, animated: true) { 
            
        }
    }
    func MineHeaderViewCollectButtonDidClick() {
        print("收藏")
    }
    func MineHeaderViewCommentButtonDidClick() {
        print("评论")
    }
    func MineHeaderViewMoreButtonDidClick() {
        print("更多")
    }
}
